package server;

/**
 * http协议工具类
 * 响应体和响应行中间是隔着一行的
 */
public class HttpProtocolUtil {
    /**
     * 为响应码200提供请求头信息
     *
     * @return
     */
    public static String getHttpHeader200(String content) {
        return "HTTP/1.1 200 OK\n"+
                "Content-Type: text/html\n"+
                "Content-Length: "+content.length()+"\n"+
                "\r\n"+
                content;
    }
    /**
     * 为响应码400提供请求头信息
     *
     * @return
     */
    public static String getHttpHeader404() {
        String str404="<h1> 404 not found";
        return "HTTP/1.1 404 NOT Found\n"+
                "Content-Type: text/html;charset=UTF-8\n"+
                "Content-Length: "+str404.length()+"\n"+
                "\r\n"
                +str404;//响应体
    }

    public static String getHttpHeader200(int resourceSize) {
        return "HTTP/1.1 200 OK\n"+
                "Content-Type: text/html;charset=UTF-8\n"+
                "Content-Length: "+resourceSize+"\n"+
                "\r\n";
    }
}
